﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AP.Framework.Infrastructure.Entities;
using AP.Framework.Infrastructure.Repositories.IRepositories;
using AP.Framework.Infrastructure.Database;
using System.Data;

namespace AP.Framework.Infrastructure.Repositories
{
    public class JobRepository : Repository<cms_Job>, IJob
    {
        protected override Func<cms_Job, object> DefaultOrderBy
        {
            get
            {
                return x => x.ID;
            }
        }

        public JobRepository(ApContext context) : base(context) { }

        public override void Add(cms_Job entity)
        {

            base.Add(entity);
        }

        public override cms_Job FindById(int id)
        {
            return (from entity in DefaultSet
                    where id == entity.ID
                    select entity).SingleOrDefault();
        }

        public override IEnumerable<cms_Job> FindById(params int[] ids)
        {
            return from entity in DefaultSet
                   where ids.Contains(entity.ID)
                   select entity;
        }
        public override void Modify(cms_Job entity)
        {
            ApContext context = new ApContext();
            var entry = context.Entry(entity);
            if (entry.State == EntityState.Detached)
            {
                entry.State = EntityState.Modified;
            }
            context.SaveChanges();
        }
        public override void Remove(cms_Job entity)
        {
            ApContext context = new ApContext();
            var entry = context.Entry(entity);
            if (entry.State == EntityState.Detached)
            {
                entry.State = EntityState.Deleted;
            }
            context.SaveChanges();
        }
    }
}
